﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;

namespace Ls.Utils
{
    public static partial class CommonHelper
    {
        public static string GetRequest(string key)
        {
            string value = "";
            try
            {
               
              
                if (SxHttpContext.Current.Request.Query.ContainsKey(key))
                {
                    value = SxHttpContext.Current.Request.Query[key];
                }
                if (SxHttpContext.Current.Request.Method.ToUpper() == "POST")
                {
                    if (SxHttpContext.Current.Request.Form.ContainsKey(key))
                    {
                        value = SxHttpContext.Current.Request.Form[key];
                    }
                }
               
                return value;
            }
            catch (Exception ex)
            {

                return value;
            }
          

        }
        public static int GetPageIndex()
        {
            int pageIndex = CommonHelper.ToInt(GetRequest("pageCurrent"), 1) - 1;
            return pageIndex < 0 ? 0 : pageIndex;
        }
      
        public static int GetPageRows()
        {
            return CommonHelper.ToInt(GetRequest("pageSize"), 20);
        }

        public static string GetSort(string defaultSort)
        {
            string sort = GetRequest("sortField");
            if (sort.IsNullOrEmpty())
            {
                return defaultSort;
            }
            string order = GetRequest("sortOrder");
            if (order.IsNullOrEmpty())
            {
                order = "asc";
            }
            return sort + " " + order;
        }
        public static string GetSort4Mg(string defaultSort)
        {
            string sort = GetRequest("sortField");
            if (sort.IsNullOrEmpty())
            {
                return defaultSort;
            }
            string order = GetRequest("sortOrder") ;
            if (order.IsNullOrEmpty())
            {
                order = "asc";
            }
            return sort + ":" + (order == "asc" ? "1" : "-1");
        }
    }
}
